package web.commons;

import domain.ImageEntry;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
 * Markup Usage:
 * <img border="0" src="" wicket:id="image" alt="Thumbnail"/>
 */
public class ImageThumbnail extends Label {
    public ImageThumbnail(String id, IModel<ImageEntry> model) {
        super(id);
        ResourceReference ref = new ResourceReference("imageResource");
        Long imageId = null;
        if (model.getObject() != null) {
            imageId = model.getObject().getId();
        }
        String url = getRequestCycle().urlFor(ref) + "/imageEntryId/" + imageId;
        url = url + "/thumbnail/true";
        AttributeModifier modifier = new AttributeModifier("src", new Model(url));

        this.add(modifier);
    }
}
